package com.example.sm.mycook.tools;

import android.util.Log;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by Administrator on 2016/12/6.
 */
public class HttpUtils {
    public static String getStringData(String string)
    {
        try {
            URL url=new URL(string);

            HttpURLConnection connection= (HttpURLConnection) url.openConnection();

            if (connection.getResponseCode()==200)
            {
                InputStream is=connection.getInputStream();

                int len=0;
                byte[] buffer=new byte[1024];
                StringBuilder builder=new StringBuilder();

                while ((len=is.read(buffer))!=-1)
                {
                    builder.append(new String(buffer,0,len));
                }
//                Log.e("AAA","下载的JsonString"+builder.toString());
                return builder.toString();

            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}
